<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>

<head>
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css">
    <script src="${ctx}/layui/jquery.js"></script>
</head>

<body>
<div class="layui-card layui-anim layui-anim-upbit">
    <div class="layui-card-header">
        <!-- <i class="layui-icon layui-icon-website" style="font-size: 30px; color: #bbbbbb;"></i> -->

        <span style="font-size: 20px;">登录</span>
    </div>
    <div class="layui-card-body">

        <form action="" class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">账号</label>
                <div class="layui-input-block">
                    <input name="username" class="layui-input" lay-verType="tips"></input>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-block">
                    <input name="password" type="password" class="layui-input" lay-verType="tips"></input>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button lay-submit class="layui-btn layui-btn-normal" lay-filter="ff">提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>

    </div>
</div>


</body>
<script src="${ctx}/layui/layui.all.js"></script>
<script>



    layui.use(['form', 'element'], function() {
        var form = layui.form;
        form.on("submit(ff)", data => {
            $.ajax({
                url:"${ctx}/login/login",
                type:"post",
                dataType:"json",
                contentType:"application/json",
                data:JSON.stringify(data.field),
                success:res=>{
                    if(res.code==1){
                        window.location.href = "${ctx}/home/index"
                    }else {
                        layer.msg(res.msg)
                    }

                },
                error:res=>{
                    alert(res.msg)
                }
            })

            return false;
        })
    })
</script>

</html>
<style>
    .layui-card {
        margin: 8% 30% 0 30%;
        background-color: #f0f0f0;
    }

    .layui-form-item {
        padding-top: 5%;
    }
</style>